package Sevlet;

import bean.person;
import util.TouristDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

public class TouristManage extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //游客编辑自己的信息(不包括修改密码)
        String id = new String(req.getParameter("id").getBytes("ISO-8859-1"),"UTF-8");
        String userName = new String(req.getParameter("userName").getBytes("ISO-8859-1"),"UTF-8");
        String password = new String(req.getParameter("password").getBytes("ISO-8859-1"),"UTF-8");
        String name = new String(req.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
        String sex = new String(req.getParameter("sex").getBytes("ISO-8859-1"),"UTF-8");
        String birth = new String(req.getParameter("birth").getBytes("ISO-8859-1"),"UTF-8");
        String nation = new String(req.getParameter("nation").getBytes("ISO-8859-1"),"UTF-8");
        String phone = new String(req.getParameter("phone").getBytes("ISO-8859-1"),"UTF-8");
        String place = new String(req.getParameter("place").getBytes("ISO-8859-1"),"UTF-8");
        TouristDao tdao = new TouristDao();
        try {
            tdao.updateTourist(userName,password, id, name, sex, birth, nation, phone, place);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            person p = tdao.get(userName);
            req.getSession().setAttribute("person", p);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        resp.sendRedirect("http://localhost:8080/tourist/info.jsp");
    }
}
